<template>
  <div class="data-center-main" ref="dataCenter">
    <div class="container">
      <div class="top">
        <div>
          <el-button type="primary" @click="batchImport"
            >批量导入/更新</el-button
          >
          <el-button type="primary" @click="handleAdd('new')"
            >新增标准值</el-button
          >
        </div>

        <div>
          <el-select
            style="width: 200px; margin-right: 20px"
            v-model="form.userId"
            placeholder="部门名称/用户名称"
          >
            <el-option
              v-for="item in initCustomer"
              :key="item.id"
              :label="item.username"
              :value="item.id"
            >
            </el-option>
          </el-select>
          <el-button
            type="primary"
            icon="el-icon-search"
            style="
              background: #5b6bf4;
              font-family: 'HarmonyOS_Sans_SC_Regular';
              border: none;
            "
            @click="getList(form.userId)"
            >搜索</el-button
          >
        </div>
      </div>
      <div style="display: flex; height: 100%">
        <div class="left">
          <el-input placeholder="搜索" suffix-icon="el-icon-search"></el-input>
          <el-tree
            :data="partTree"
            style="margin-bottom: 10px; margin-top: 10px"
          ></el-tree>
          <!-- :props="defaultProps" -->
        </div>
        <div class="right">
          <el-table
            :data="tableList"
            class="standard"
            height="400"
            v-loading="loading"
          >
            <el-table-column type="selection" width="55" align="center">
            </el-table-column>
            <el-table-column prop="tacticsName" label="策略名称" align="center">
            </el-table-column>
            <!-- <el-table-column prop="saturation" label="饱和度" align="center">
                        </el-table-column> -->
            <el-table-column prop="purity" label="纯净度" align="center">
            </el-table-column>
            <el-table-column
              prop="goldenPosLayer"
              label="黄金位"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="goldenPurity"
              label="黄金位纯度"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="Saturation" label="饱和度" align="center">
            </el-table-column>
            <el-table-column
              prop="requiredShopRate"
              label="必铺品率"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="surprisingProportion"
              label="竟占比"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="application" label="应用范围" align="center">
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleEdit(scope.row)"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  style="color: red"
                  @click="openConfirm(scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <!-- <div class="page">
                        <div style="margin-right: 20px;color: #333;font-family:'HarmonyOS_Sans_SC_Regular'">共7条</div>
                        <el-button type="text" style="color:#333;margin-right: 10px;">
                            << /el-button>
                                <div class="pageborder">1</div>
                                <el-button type="text" style="color:#333;margin-right: 10px;">></el-button>
                                <div style="margin-right: 10px;color: #333;font-family:'HarmonyOS_Sans_SC_Regular'">前往
                                </div>
                                <el-input type="number" style="width: 60px;margin-right: 10px;" :min="0"
                                    v-model="pageIndex" />

                                <div style="color: #333;font-family:'HarmonyOS_Sans_SC_Regular'">页</div>
                    </div> -->
        </div>
      </div>
      <!-- 新建部门 -->
      <el-drawer title="新建部门" :visible.sync="departmentAddDrawer">
        <el-form
          ref="form"
          :model="partmentAddForm"
          :rules="partmentAddrules"
          label-width="110px"
          style="width: 95%; padding-left: 25px"
          label-position="left"
        >
          <el-form-item label="部门名称" prop="partmentName">
            <el-input
              v-model="partmentAddForm.partmentName"
              placeholder="请输入部门姓名"
            />
          </el-form-item>
          <el-form-item label="上级部门" prop="supDepartment">
            <el-input
              v-model="partmentAddForm.supDepartment"
              placeholder="请输入上级部门"
              clearable
            />
          </el-form-item>
          <el-form-item label="部门负责人" prop="leader">
            <el-input
              v-model="partmentAddForm.leader"
              placeholder="请输入联系方式"
              clearable
            />
          </el-form-item>
          <el-form-item label="部门团队" prop="mail"> </el-form-item>
          <div style="color: #aaa">
            <span
              >此团队人员会根据部门人员变化自动同步，若成员不在部门中，则不会加入部门团队</span
            >
            <div class="group">
              <div>团队名称</div>
              <el-input
                v-model="partmentAddForm.leader"
                placeholder="请输入"
                clearable
                style="width: 70%"
              />
            </div>
            <div class="group" style="margin-bottom: 20px">
              <div>团队拥有者</div>
              <el-input
                v-model="partmentAddForm.leader"
                placeholder="第一个部门成员将成为拥有者"
                clearable
                style="width: 70%"
              />
            </div>
          </div>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="partmentAddForm.remark" placeholder="请输入" />
          </el-form-item>
        </el-form>
        <div style="position: absolute; right: 5%">
          <el-button
            style="font-family: 'HarmonyOS_Sans_SC_Regular'"
            @click="batchImportOpen = false"
            >取消</el-button
          >
          <el-button
            type="primary"
            style="
              background: #5b6bf4;
              font-family: 'HarmonyOS_Sans_SC_Regular';
              border: none;
            "
            @click="batchImportOpen = false"
            >确定</el-button
          >
        </div>
      </el-drawer>
      <!-- 修改 -->
      <el-drawer title="修改" :visible.sync="modifyDrawer">
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          label-width="110px"
          style="width: 95%; padding-left: 25px"
          label-position="left"
        >
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入姓名" />
          </el-form-item>
          <el-form-item label="部门" prop="partment">
            <el-select
              v-model="form.partment"
              placeholder="请选择"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in partList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="手机" prop="phoneNumber">
            <el-input
              v-model="form.phoneNumber"
              placeholder="请输入联系方式"
              clearable
            />
          </el-form-item>
          <el-form-item label="邮箱" prop="mail">
            <el-input v-model="form.mail" placeholder="请输入门店编号" />
          </el-form-item>
          <el-form-item label="别名" prop="nickName">
            <el-input v-model="form.nickName" placeholder="请输入别名" />
          </el-form-item>
          <el-form-item label="职务" prop="post">
            <el-input v-model="form.post" placeholder="请输入店主名称" />
          </el-form-item>
          <el-form-item label="直属上司" prop="supervisor">
            <el-select
              v-model="form.partment"
              placeholder="请选择"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in partList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="人员类型" prop="type">
            <el-select
              v-model="form.partment"
              placeholder="请选择"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in partList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="工号" prop="jobNumber">
            <el-input v-model="form.jobNumber" placeholder="请输入工号" />
          </el-form-item>
        </el-form>
        <div style="position: absolute; right: 5%">
          <el-button
            style="font-family: 'HarmonyOS_Sans_SC_Regular'"
            @click="batchImportOpen = false"
            >取消</el-button
          >
          <el-button
            type="primary"
            style="
              background: #5b6bf4;
              font-family: 'HarmonyOS_Sans_SC_Regular';
              border: none;
            "
            @click="batchImportOpen = false"
            >确定</el-button
          >
        </div>
      </el-drawer>
      <!-- 批量导入 -->
      <el-dialog
        :visible.sync="batchImportOpen"
        width="800px"
        append-to-body
        :show-close="false"
      >
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="批量导入" name="first">
            <el-timeline>
              <el-timeline-item timestamp="下载组织架构模板" placement="top">
                <div class="download">
                  <span
                    style="
                      font-family: 'HarmonyOS_Sans_SC_Regular';
                      color: #777;
                    "
                    >请下载模板，按照模板格式要求编辑后上传，完成导入</span
                  >
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-download"
                    style="
                      color: #5b6bf4;
                      font-family: 'HarmonyOS_Sans_SC_Regular';
                    "
                    >下载模板</el-button
                  >
                </div>
              </el-timeline-item>
              <el-timeline-item timestamp="上传文件" placement="top">
                <div
                  style="
                    display: flex;
                    align-items: center;
                    width: 100%;
                    height: 100%;
                    flex-direction: column;
                  "
                >
                  <el-upload
                    action="https://jsonplaceholder.typicode.com/posts/"
                    list-type="picture-card"
                  >
                    <!-- :on-preview="handlePictureCardPreview" :on-remove="handleRemove"> -->
                    <img
                      src="../../../../assets/images/file.png"
                      style="width: 50px"
                    />
                    <!-- <i class="el-icon-plus"></i> -->
                  </el-upload>
                  <el-button
                    type="primary"
                    style="
                      background: #5b6bf4;
                      font-family: 'HarmonyOS_Sans_SC_Regular';
                      border: none;
                      margin-top: 10px;
                      width: 148px;
                    "
                    >上传文件</el-button
                  >
                </div>
              </el-timeline-item>
            </el-timeline>
          </el-tab-pane>
          <el-tab-pane label="批量跟新" name="second">批量更新</el-tab-pane>
        </el-tabs>
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
          "
        >
          <div style="font-family: 'HarmonyOS_Sans_SC_Regular'; color: #777">
            导入部门时创建对应的部门团队
          </div>
          <div>
            <el-button
              style="font-family: 'HarmonyOS_Sans_SC_Regular'"
              @click="batchImportOpen = false"
              >取消</el-button
            >
            <el-button
              type="primary"
              style="
                background: #5b6bf4;
                font-family: 'HarmonyOS_Sans_SC_Regular';
                border: none;
              "
              >开始导入</el-button
            >
          </div>
        </div>
      </el-dialog>
      <!-- 调整部门 -->
      <el-dialog
        :visible.sync="adjustOpen"
        width="630px"
        append-to-body
        :show-close="false"
      >
        <div style="display: flex; width: 100%; height: 360px">
          <div
            style="
              width: 50%;
              height: 100%;
              border-right: 1px solid #eee;
              padding-right: 10px;
            "
          >
            <el-input
              placeholder="搜索"
              suffix-icon="el-icon-search"
            ></el-input>
            <el-tree
              :data="partTree"
              @check-change="handleCheckChange"
              node-key="id"
              default-expand-all
              :expand-on-click-node="false"
            >
              <span
                slot-scope="{ node }"
                style="display: flex; justify-content: space-between; flex: 1"
              >
                <span>{{ node.label }}</span>
                <span>
                  <el-checkbox
                    :checked="checkedMore.includes(node.id)"
                    @change="handleCheckChange(node)"
                  />
                </span>
              </span>
            </el-tree>
          </div>
          <div style="width: 50%; height: 100%; color: #aaa; padding: 0px 20px">
            <div
              style="font-size: 15px; font-family: 'HarmonyOS_Sans_SC_Regular'"
            >
              已选择两项
            </div>
            <div
              v-for="item in partUpdateList"
              :key="item.id"
              style="
                margin-top: 10px;
                font-family: 'HarmonyOS_Sans_SC_Regular';
                display: flex;
                justify-content: space-between;
              "
            >
              {{ item }}
              <img
                src="../../../../assets/images/del.png"
                style="width: 20px"
                @click="del(item)"
              />
            </div>
          </div>
          <!-- <el-transfer filterable :filter-method="filterMethod" filter-placeholder="搜索" v-model="value" :data="data">
                </el-transfer> h:360-->
          <div
            style="position: absolute; right: 5%; bottom: 1%; margin-top: 10px"
          >
            <el-button
              style="font-family: 'HarmonyOS_Sans_SC_Regular'"
              @click="adjustOpen = false"
              >取消</el-button
            >
            <el-button
              type="primary"
              style="
                background: #5b6bf4;
                font-family: 'HarmonyOS_Sans_SC_Regular';
                border: none;
              "
              @click="adjustOpen = false"
              >确定</el-button
            >
          </div>
        </div>
      </el-dialog>
      <el-dialog
        :title="dialogTitle"
        :visible.sync="dialogOpen"
        @close="closeDialog"
        width="800px"
        append-to-body
      >
        <el-form
          ref="standardForm"
          :model="standardForm"
          :rules="standardFormRule"
          label-width="120px"
        >
          <el-row style="display: flex; flex-wrap: wrap">
            <el-col :span="12">
              <el-form-item label="用户名" prop="userId">
                <!-- <el-input v-model="standardForm.userId"></el-input> -->
                <el-select
                  v-model="standardForm.userId"
                  filterable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in initCustomer"
                    :key="item.id"
                    :label="item.username"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="柜子型号" prop="containerTypeName">
                <!-- <el-input v-model="standardForm.userId"></el-input> -->
                <el-select
                  v-model="containerTypeId"
                  filterable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in initContainerType"
                    :key="item.id"
                    :label="item.model"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12" v-for="item in options" :key="item.value">
              <el-form-item :label="item.label" :prop="item.value">
                <!-- <el-form-item :label="item.label" prop="cunjing"> -->
                <el-input
                  v-model.number="standardForm[item.value]"
                  :placeholder="item.placeHolder"
                  type="number"
                  style="width: 200px"
                >
                  <template slot="append" v-if="item.append">{{
                    item.append
                  }}</template>
                </el-input>
              </el-form-item>
            </el-col>

            <el-form-item label="黄金位层数">
              <el-checkbox-group v-model="goldLayerList">
                <el-checkbox label="1" value="1"></el-checkbox>
                <el-checkbox label="2" value="2"></el-checkbox>
                <el-checkbox label="3" value="3"></el-checkbox>
                <el-checkbox label="4" value="4"></el-checkbox>
                <el-checkbox label="5" value="5"></el-checkbox>
                <el-checkbox label="6" value="6"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
          <el-row> </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="submitUser">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="修改标准值"
        :visible.sync="dialogEditOpen"
        @close="closeEditDialog"
        append-to-body
        v-loading="loading"
      >
        <div style="min-height: 100px">
          <!-- :rules="standardEditFormRule" -->
          <el-form
            ref="standardEditForm"
            :model="standardEditForm"
            :rules="calRules"
            label-width="120px"
            destroy-on-close
          >
            <el-row style="display: flex; flex-wrap: wrap">
              <el-col :span="12">
                <el-form-item label="用户名" prop="userId">
                  <!-- <el-input v-model="standardForm.userId"></el-input> -->
                  <el-select
                    v-model="standardEditForm.userId"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in initCustomer"
                      :key="item.id"
                      :label="item.username"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="柜子型号" prop="containerTypeName">
                  <!-- <el-input v-model="standardForm.userId"></el-input> -->
                  <el-select
                    v-model="standardEditForm.containerTypeId"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in initContainerType"
                      :key="item.id"
                      :label="item.model"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="纯净度" prop="purity">
                  <el-input
                    v-model="standardEditForm.purity"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="饱和度" prop="saturation">
                  <el-input
                    v-model="standardEditForm.saturation"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="黄金位纯度" prop="goldenPosPurity">
                  <el-input
                    v-model="standardEditForm.goldenPosPurity"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="缺货率" prop="stockOutRate">
                  <el-input
                    v-model="standardEditForm.stockOutRate"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="必铺品率" prop="biPuPinRate">
                  <el-input
                    v-model="standardEditForm.biPuPinRate"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>

              <!-- <el-col :span="12" v-for="item in options" :key="item.value">
            <el-form-item :label="item.label" :prop="item.value">
              <el-input
                v-model.number="standardEditForm[item.value]"
                :placeholder="item.placeHolder"
                type="number"
                style="width: 200px"
              >
                <template slot="append" v-if="item.append">{{
                  item.append
                }}</template>
              </el-input>
            </el-form-item>
          </el-col> -->

              <el-form-item label="黄金位层数" prop="goldLayerList">
                <el-checkbox-group
                  v-model="standardEditForm.goldLayerList"
                  @change="handleCheckedLayerChange"
                >
                  <el-checkbox label="1" value="1"></el-checkbox>
                  <el-checkbox label="2" value="2"></el-checkbox>
                  <el-checkbox label="3" value="3"></el-checkbox>
                  <el-checkbox label="4" value="4"></el-checkbox>
                  <el-checkbox label="5" value="5"></el-checkbox>
                  <el-checkbox label="6" value="6"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-row>
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancelEditUser">取 消</el-button>
          <el-button type="primary" @click="submitEditUser">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="修改标准值"
        :visible.sync="dialogEditOpen"
        @close="closeEditDialog"
        append-to-body
      >
        <div style="min-height: 100px">
          <!-- :rules="standardEditFormRule" -->
          <el-form
            ref="standardEditForm"
            :model="standardEditForm"
            :rules="calRules"
            label-width="120px"
            destroy-on-close
          >
            <el-row style="display: flex; flex-wrap: wrap">
              <el-col :span="12">
                <el-form-item label="用户名" prop="userId">
                  <!-- <el-input v-model="standardForm.userId"></el-input> -->
                  <el-select
                    v-model="standardEditForm.userId"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in initCustomer"
                      :key="item.id"
                      :label="item.username"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="柜子型号" prop="containerTypeName">
                  <!-- <el-input v-model="standardForm.userId"></el-input> -->
                  <el-select
                    v-model="standardEditForm.containerTypeId"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in initContainerType"
                      :key="item.id"
                      :label="item.model"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="纯净度" prop="purity">
                  <el-input
                    v-model="standardEditForm.purity"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="饱和度" prop="saturation">
                  <el-input
                    v-model="standardEditForm.saturation"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="黄金位纯度" prop="goldenPosPurity">
                  <el-input
                    v-model="standardEditForm.goldenPosPurity"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="缺货率" prop="stockOutRate">
                  <el-input
                    v-model="standardEditForm.stockOutRate"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="必铺品率" prop="biPuPinRate">
                  <el-input
                    v-model="standardEditForm.biPuPinRate"
                    type="number"
                    placeholder="请输入"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-form-item label="黄金位层数" prop="goldLayerList">
                <el-checkbox-group
                  v-model="standardEditForm.goldLayerList"
                  @change="handleCheckedLayerChange"
                >
                  <el-checkbox label="1" value="1"></el-checkbox>
                  <el-checkbox label="2" value="2"></el-checkbox>
                  <el-checkbox label="3" value="3"></el-checkbox>
                  <el-checkbox label="4" value="4"></el-checkbox>
                  <el-checkbox label="5" value="5"></el-checkbox>
                  <el-checkbox label="6" value="6"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-row>
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancelEditUser">取 消</el-button>
          <el-button type="primary" @click="submitEditUser">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// import {
//     pmStandardModify,
//     pmStandardList,
//     pmStandardView, // view 还可以查询指标
//     pmStandardDelete,
//     pmStandardAdd,
//     pmStandardAddBatch,
//     displaySpecAdd,
//     displaySpecModify,
//     displaySpecDel,
//     displaySpecGet,
//     listCustomer,
// } from '@/api/customer/customer'
// import {
//     getBiPuPin
// } from '@/api/goods/SKU'
// import { getToken } from '@/utils/auth'
// import { getUserInfoByToken } from '@/api/user/index'
// import { tansParams } from '@/utils/ruoyi'
// import { containerTypeAdd, containerTypeList } from '@/api/container/index'
const needCheck = ["纯净度", "饱和度", "黄金位纯度"];
const defaultRule = {
  message: "标准值范围0-100",
  trigger: "blur",
  min: 0,
  max: 100,
};
export default {
  components: {},
  data() {
    const generateData = (_) => {
      const data = [];
      const cities = ["浙江商识信息技术有限公司", "算法"];
      const pinyin = ["shangshi", "algorithm"];
      cities.forEach((city, index) => {
        data.push({
          label: city,
          key: index,
          pinyin: pinyin[index],
        });
      });
      return data;
    };
    return {
      containerTypeId: "",
      userId: "",
      goldLayerList: [],
      tableList: [
        {
          id: "",
          userId: "",
          bipupinCount: "",
          userName: "",
          containerTypeId: "",
          goldenPosLayer: "",
          goldenPosPurity: "",
          purity: "",
          saturation: "",
          stockOutRate: "",
          createTime: "",
        },
      ],
      rowBiPuPin: [],
      initContainerType: [],
      initCustomer: [],
      list: [],
      loading: false,
      dialogOpen: false, // 弹窗开关
      dialogEditOpen: false, // 弹窗开关
      showBiPuPinDialog: false, //必铺品窗口开关
      standardForm: {
        target: "纯净度",
        userId: "",
        value: "",
      },
      standardEditForm: {
        target: "纯净度",
        userId: "",
        value: "",
      },
      standardEditFormRule: {
        value: [
          { required: true, message: "请输入", trigger: "blur" },
          defaultRule,
        ],
      },
      standardEditFormRuleSingle: {
        value: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      //dialogTitle: '',
      form: {
        userId: "",
      },
      standardFormRule: {
        userId: [{ required: true, message: "请输入", trigger: "blur" }],
        // '纯净度': [defaultRule],
        // '黄金位纯度': [defaultRule],
        // '饱和度': [defaultRule],
      },
      options: [
        //   纯净度、饱和度、黄金位纯度、缺货、必铺品
        {
          label: "纯净度",
          value: "纯净度",
          key: "1",
          placeHolder: "请输入",
          append: "%",
          prop: "cunjing",
        },
        {
          label: "饱和度",
          value: "饱和度",
          key: "2",
          placeHolder: "请输入",
          append: "%",
          prop: "baohe",
        },
        {
          label: "黄金位纯度",
          value: "黄金位纯度",
          key: "3",
          placeHolder: "请输入",
          append: "%",
          prop: "huangjing",
        },

        {
          label: "缺货率",
          value: "缺货率",
          key: "4",
          placeHolder: "请输入",
          append: "%",
          prop: "quehuo",
        },
        {
          label: "必铺品率",
          value: "必铺品率",
          key: "5",
          placeHolder: "请输入",
          append: "%",
          prop: "bipupin",
        },
      ],
      formLabel: "",
      needCheck,
      loading: false,
      adjustOpen: false,
      data: generateData(),
      value: [],
      pageIndex: "1",
      filterMethod(query, item) {
        return item.pinyin.indexOf(query) > -1;
      },
      partTree: [
        {
          label: "浙江商识信息技术有限公司",
          children: [
            {
              label: "算法",
            },
          ],
        },
      ],
      partUpdateList: ["浙江商识信息技术有限公司", "算法"],
      checkedMore: [],
      partList: [
        {
          label: "算法",
          value: "算法",
        },
        {
          label: "研发",
          value: "研发",
        },
        {
          label: "硬件",
          value: "硬件",
        },
        {
          label: "运维",
          value: "运维",
        },
        {
          label: "软件",
          value: "软件",
        },
      ],
      partName: "",
      list: [],
      partMember: "",
      partStatus: "",
      memberList: [
        {
          label: "星小眸",
          value: "星小眸",
        },
        {
          label: "张",
          value: "张",
        },
        {
          label: "王",
          value: "王",
        },
        {
          label: "刘",
          value: "刘",
        },
        {
          label: "林",
          value: "林",
        },
      ],
      statusList: [
        {
          label: "工作",
          value: "工作",
        },
        {
          label: "休息",
          value: "休息",
        },
        {
          label: "出差",
          value: "出差",
        },
      ],
      batchImportOpen: false,
      activeName: "first",
      departmentAddDrawer: false, //新建部门右侧抽屉
      modifyDrawer: false, //修改右侧抽屉
      form: {}, //修改的表单内数据
      partmentAddForm: {}, //新建部门表单
      rules: {
        name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
        partment: [
          { required: true, message: "部门不能为空", trigger: "blur" },
        ],
        phoneNumber: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
        ],
      },
      partmentAddrules: {
        partmentName: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],
        supDepartment: [
          { required: true, message: "部门不能为空", trigger: "blur" },
        ],
        leader: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
        ],
      },
      standard: [
        {
          tacticsName: "111",
          saturation: "30%",
          purity: "30%",
          gloden: "1-7",
          mustSell: "30%",
          compete: "30%",
          application: "本部门",
        },
        {
          tacticsName: "111",
          saturation: "30%",
          purity: "30%",
          gloden: "1-7",
          mustSell: "30%",
          compete: "30%",
          application: "本部门",
        },
        {
          tacticsName: "111",
          saturation: "30%",
          purity: "30%",
          gloden: "1-7",
          mustSell: "30%",
          compete: "30%",
          application: "本部门",
        },
        {
          tacticsName: "111",
          saturation: "30%",
          purity: "30%",
          gloden: "1-7",
          mustSell: "30%",
          compete: "30%",
          application: "本部门",
        },
        {
          tacticsName: "111",
          saturation: "30%",
          purity: "30%",
          gloden: "1-7",
          mustSell: "30%",
          compete: "30%",
          application: "本部门",
        },
        {
          tacticsName: "111",
          saturation: "30%",
          purity: "30%",
          gloden: "1-7",
          mustSell: "30%",
          compete: "30%",
          application: "本部门",
        },
        {
          tacticsName: "111",
          saturation: "30%",
          purity: "30%",
          gloden: "1-7",
          mustSell: "30%",
          compete: "30%",
          application: "本部门",
        },
      ],
    };
  },
  mounted() {
    // this.getList()
    // listCustomer().then((res) => {
    //     let that = this
    //     that.initCustomer = res.data.data
    //     that.form.userId = that.initCustomer[0].id
    //     getUserInfoByToken({ token: getToken }).then((res) => [
    //         that.getList(res.data.id),
    //         that.userId = res.data.id
    //     ])
    // })
  },
  computed: {
    dialogTitle() {},
    calRules() {
      return this.standardForm.target.includes("度")
        ? this.standardEditFormRule
        : this.standardEditFormRuleSingle;
    },
  },

  beforeDestroy() {},
  methods: {
    /** 时间格式转换 */
    formateTime(time) {
      console.log(time);
      //将时间戳格式转换成年月日时分秒
      var date = new Date(time);
      var Y = date.getFullYear() + "-";
      var M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";

      var h =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      var m =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      var s =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      var strDate = Y + M + D + h + m + s;

      console.log(strDate);
      return strDate;
    },
    /** 黄金层点击 */
    handleCheckedLayerChange(val) {
      //排序一下
      this.standardEditForm.goldLayerList.sort();
    },
    //点击必铺品数量显示所有必铺品
    handleShowbiPuPin(row) {
      console.log("用户token", getToken);
      console.log("用户id信息为：", row.userId);
      this.showBiPuPinDialog = true;
      getBiPuPin({ userId: row.userId, token: getToken })
        .then((res) => {
          console.log("## 获取所有必铺品 ==> ", res);
          this.rowBiPuPin = res.data;
          this.$message.success("必铺品列表获取成功");
        })
        .catch((err) => {
          this.$message.error(err.message || "必铺品列表获取失败");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    cancelEditUser() {
      // 取消用户编辑
      this.dialogEditOpen = false;
    },
    submitEditUser() {
      this.$refs.standardEditForm.validate((valid) => {
        console.log("## editform ==>", this.standardEditForm);
        if (!valid) {
          return;
        }
        let gd = "";
        gd = this.standardEditForm.goldLayerList.join(",");
        const params = {
          userId: this.standardEditForm.userId,
          id: this.standardEditForm.id,
          goldenPosLayer: gd,
          purity: parseInt(this.standardEditForm.purity),
          saturation: parseInt(this.standardEditForm.saturation),
          goldenPosPurity: parseInt(this.standardEditForm.goldenPosPurity),
          stockOutRate: parseInt(this.standardEditForm.stockOutRate),
          biPuPinRate: parseInt(this.standardEditForm.biPuPinRate),
        };
        displaySpecModify(params)
          .then((res) => {
            console.log("修改结果", res);
          })
          .catch((err) => {
            this.$message.error(err.message || "修改失败");
          })
          .finally(() => {
            this.dialogEditOpen = false;
            this.getList(this.form.userId);
          });
      });
    },
    handleGroupChange(value) {
      //
      console.log("## value ==>", value);
    },
    openConfirm(row) {
      // this.$confirm
      this.$confirm("是否删除？", "提示", {
        distinguishCancelAndClose: true,
        confirmButtonText: "确认",
        cancelButtonText: "取消",
      })
        .then(() => {
          this.handleDel(row);
        })
        .catch(() => {});
    },
    handleDel(row) {
      console.log(row);
      this.loading = true;
      const params = {
        id: row.id,
      };
      displaySpecDel(params)
        .then((res) => {
          console.log("## deleteCustomer ==> ", res);
          this.getList(this.form.userId);
          this.$message.success("删除成功");
        })
        .catch((err) => {
          this.$message.error(err.message || "删除失败");
        })
        .finally(() => {
          this.loading = false;
        });
    },

    handleEdit(row) {
      console.log(row);
      //初始化清空柜子类型
      this.standardEditForm = {};
      this.initContainerType = [];
      //获取柜子类型列表
      const params = {
        userId: row.userId,
        token: getToken,
      };
      containerTypeList(params).then((res) => {
        console.log("柜子类型有:", res);
        this.initContainerType = res.data;
      });
      let gd = [];
      gd = row.goldenPosLayer.split(",");
      this.standardEditForm = {
        userId: row.userId,
        containerTypeId: row.containerTypeId,
        id: row.id,
        goldenPosLayer: row.goldenPosLayer,
        purity: parseInt(row.purity),
        saturation: parseInt(row.saturation),
        goldenPosPurity: parseInt(row.goldenPosPurity),
        stockOutRate: parseInt(row.stockOutRate),
        biPuPinRate: parseInt(row.biPuPinRate),
        goldLayerList: gd,
      };
      this.dialogEditOpen = true;
    },
    standardVo2Dto(value) {
      //       {
      //   "targets": [
      //     {
      //       "target": "string",
      //       "value": 0
      //     }
      //   ],
      //   "userId": 0
      // }
      const ret = {
        userId: value.userId,
      };
      const field = this.options.map((item) => item.label);
      const targets = field
        .map((item) => {
          if (!value[item] && value[item] !== 0) return null;
          return {
            target: item,
            value: value[item],
          };
        })
        .filter((item) => item);
      ret.targets = targets;
      return ret;
    },
    submitUser() {
      console.log("处理前的data", this.standardForm);
      this.$refs.standardForm.validate((valid) => {
        if (!valid) return;
        const data = this.standardVo2Dto(this.standardForm);
        console.log("处理后的data");
        data.goldenPosLayer = this.goldLayerList.join(",");
        data.containerTypeId = this.containerTypeId;
        console.log("## valid ==>", valid, this.standardForm, data);
        if (Array.isArray(data.targets) && !data.targets.length) {
          this.$message.error("请填写标准值");
          return;
        }
        // return
        // const params = {
        //   ...this.standardForm,
        // }
        // console.log('## params ==>', params)

        //新增陈列标准值接口
        const service = displaySpecAdd;
        this.loading = true;
        console.log("## 传入接口的值 ==>", data);
        const params = {
          containerTypeId: data.containerTypeId.toString(),
          goldenPosLayer: data.goldenPosLayer,
          purity: data.targets[0].value.toString(),
          goldenPosPurity: data.targets[1].value.toString(),
          saturation: data.targets[2].value.toString(),
          stockOutRate: data.targets[3].value.toString(),
          biPuPinRate: data.targets[4].value.toString(),
          userId: data.userId,
        };
        console.log(params);
        service(params)
          .then((res) => {
            console.log("## res ==> ", res);
            // todos 更新列表数据
            // this.getData({
            //   pageIndex: 0,
            // })
            this.$message.success("创建成功");
            this.getList(this.form.userId);
          })
          .catch((err) => {
            this.$message.error(err.message || "创建失败");
            console.log("## err ==>", err);
            // this.list = res.data
          })
          .finally(() => {
            // todos
            this.dialogOpen = false;
            this.loading = false;
            this.clearObj();
          });
      });
    },
    cancelUser() {
      this.dialogOpen = false;
      // this.clearObj()
    },
    // 清空表单数据
    clearObj() {
      Object.keys(this.standardForm).forEach((item) => {
        this.standardForm[item] = "";
      });
    },
    handleAdd(type) {
      this.dialogOpen = true;
      console.log("当前用户id为：", this.userId, getToken);
      if (this.userId === 1) {
        this.userId = "";
      }
      //加载柜子型号
      const params = {
        userId: this.userId,
        token: getToken,
      };
      console.log("柜子类型传参", params);
      containerTypeList(params).then((res) => {
        console.log("柜子类型有:", res);
        this.initContainerType = res.data;
      });
    },
    getList(userId) {
      this.loading = true;
      this.tableList = [];
      const params = {
        userId: userId,
      };
      console.log(params);
      displaySpecGet(params)
        .then((res) => {
          console.log(res);
          for (var i = 0; i < res.data.length; i++) {
            let tableListTemp1 = {
              id: "",
              bipupinCount: "",
              userName: "",
              containerTypeId: "",
              goldenPosLayer: "",
              goldenPosPurity: "",
              purity: "",
              saturation: "",
              stockOutRate: "",
              biPuPinRate: "",
              createTime: "",
            };
            tableListTemp1.id = res.data[i].id;
            tableListTemp1.bipupinCount = res.data[i].bipupinCount;
            tableListTemp1.purity = res.data[i].purity;
            if (res.data[i].user) {
              tableListTemp1.userName = res.data[i].user.username;
              tableListTemp1.userId = res.data[i].user.id;
            }
            tableListTemp1.createTime = res.data[i].createTime;
            tableListTemp1.goldenPosLayer = res.data[i].goldenPosLayer;
            tableListTemp1.goldenPosPurity = res.data[i].goldenPosPurity;
            tableListTemp1.saturation = res.data[i].saturation;
            tableListTemp1.stockOutRate = res.data[i].stockOutRate;
            if (res.data[i].containerType) {
              tableListTemp1.containerTypeId = res.data[i].containerType.id;
            }
            tableListTemp1.biPuPinRate = res.data[i].biPuPinRate;
            this.tableList.push(tableListTemp1);
          }
        })
        .finally(() => {
          this.loading = false;
        });
      this.tableList.shift();
    },
    queryByForm() {
      if (this.form.userId === "") {
        this.$message.info("请输入用户id");
        return;
      }
      console.log(this.form.userId);
      this.getList(this.form.userId);
    },
    closeEditDialog() {},
    batchImport() {
      this.batchImportOpen = true;
    },
    handleClick() {},
    submitForm() {
      this.modifyDrawer = false;
    },
    cancel() {
      this.modifyDrawer = false;
    },
    handleCheckChange(node) {
      console.log("node", node.id);
      console.log("this.checkedMore", this.checkedMore);

      if (this.checkedMore.includes(node.id)) {
        this.partUpdateList.map((e, index) => {
          if (e == node.label) {
            console.log("index", index);
            this.partUpdateList.splice(index, 1);
          }
        });
        this.checkedMore.splice(this.checkedMore.indexOf(node.id), 1);
      } else {
        this.partUpdateList.push(node.label);
        this.checkedMore.push(node.id);
      }

      // if(data.checked){ ///???如何过去选中状态
      //     console.log('data', data);
      // this.partUpdateList.push(data.label)
      // }else{
      //     this.partUpdateList.splice(1, 1)
      // }
    },
    closeDialog() {
      this.dialogOpen = false;
    },
    del(item) {
      console.log("item", item);
      this.partUpdateList.map((e, index) => {
        if (e == item) {
          console.log("index", index);

          this.partUpdateList.splice(index, 1);
        }
      });
      //this.partUpdateList.splice(id,1)
    },
  },
};
</script>

<style lang="scss" scoped>
.data-center-main {
  background-color: #f3f3f3;
  width: 100%;
  height: calc(100vh - 85px);
  display: flex;
  padding: 1%;
}

.container {
  width: 100%;
  height: 100%;
  background-color: white;
  //padding:15px
}

.top {
  width: 100%;
  height: 10%;
  border-bottom: 1px solid #e8e8e8;
  //border: solid 1px red;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid #d7d7d7;
}

.left {
  width: 20%;
  height: 90%;
  display: flex;
  flex-direction: column;
  padding: 15px;
  border-right: 1px solid #d7d7d7;
  // border-top: 1px solid #D7D7D7;
}

::v-deep .el-tree > .el-tree-node > .el-tree-node__content {
  background-color: #5b6bf4 8%;
}

//树形结构一级背景
.right {
  width: 79%;
  height: 90%;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
  padding-left: 10px;
}

.right-top {
  width: 100%;
  height: 100px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #d7d7d7;
  padding-left: 15px;
}

// ::v-deep .el-dialog__header {
//     padding: 0px;
// }

// ::v-deep .el-dialog__body {
//     padding: 1 20px;
// }

::v-deep .el-upload {
  display: flex;
  text-align: center;
  cursor: pointer;
  outline: none;
  justify-content: center;
  align-items: center;
}

::v-deep .el-upload--picture-card {
  background-color: white; // border: 1px dashed #c0ccda;
}

::v-deep .el-drawer__header {
  background-color: #7e8eff;
  color: white;
  display: flex;
  margin-bottom: 32px;
  padding: 20px;
  padding-bottom: 20px;
  align-items: center;
  font-family: "HarmonyOS_Sans_SC_Regular";
}

.download {
  width: 500px;
  height: 60px;
  background-color: rgba(91, 107, 244, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
}

.group {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: "HarmonyOS_Sans_SC_Regular";
}

.group > div {
  width: 25%;
  height: 36px;
  background: rgba(91, 107, 244, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.page {
  display: flex;
  height: 80px;
  width: 80%;
  justify-content: center;
  align-items: center;
  box-shadow: 0px -2px 3px 0px rgba(0, 0, 0, 0.02);
  bottom: 10px;
  position: absolute;
}

.pageborder {
  margin-right: 10px;
  border: 1px solid #dcdfe6;
  width: 40px;
  height: 36px;
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #333;
  font-family: "HarmonyOS_Sans_SC_Regular";
}

::v-deep .el-input__inner::-webkit-outer-spin-button,
::v-deep .el-input__inner::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

::v-deep .el-input__inner[type="number"] {
  -moz-appearance: textfield;
}
</style>
